pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let (num_str, base) = num_str.split_once("(").unwrap();
    let (base_of_str, _) = base.split_once(")").unwrap();
    let base = base_of_str.parse::<u32>().unwrap();
    let num_str_iter = num_str.chars().into_iter();
    let len = num_str.len();
    let mut total_value = 0;
    for (i, c) in num_str_iter.enumerate() {
        let digit = c.to_string().parse::<u32>().unwrap();
        let power = len - i - 1;
        if digit == 0 {
            continue;
        }
        total_value += digit * (base as u32).pow(power as u32);

    }
    let mut arr = [0;32];
    let mut quotiet = 0;
    let _ = divide(total_value, to_base,&mut quotiet, 0);
    for i in (0..quotiet + 1).rev() {
        loop {
            if total_value >= to_base.pow(i as u32) {
                total_value -= to_base.pow(i as u32);
                arr[31 - i] += 1;
            } else {
                break
            }
        }
    }
    arr[31] += total_value;
    let result = arr.iter().fold(String::from(""), |mut acc, x| {
        if acc.len() > 0 {
            char::from_digit(*x, to_base).map(|c| acc.push(c));
        } else {
            if x > &0 {
                char::from_digit(*x, to_base).map(|c| acc.push(c));
            }
        }
        acc
    });
    result
}

fn divide(total_value:u32, to_base: u32, acc:&mut usize, remainder:u32)->u32{
    let quotiet = total_value / to_base;
    let remainder = if remainder >0 {remainder} else { total_value % to_base };
    if quotiet > 0 {
        *acc += 1;
        divide(quotiet, to_base, acc, remainder)
    } else {
        return remainder;
    }
}
